<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="com.travelsky.airchina.boarding.domain.NewsColumn"%>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>管理中心 - 修改栏目</title>
	<%@ include file="/common/meta.jsp" %>
	<link href="${ctx}/css/system/general.css" rel="stylesheet" type="text/css" />
	<link href="${ctx}/css/system/main.css" rel="stylesheet" type="text/css" />
	<link href="${ctx}/css/system/category.css" rel="stylesheet" type="text/css" />	
	<script type="text/javascript" src="${ctx}/js/checkFrameSet.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery-1.4.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/json.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/update_category.js">
    </script>
	<script language="JavaScript">
	var contextPath = "${ctx}";
	 $(document).ready(findCategoryList); 
	</script>
      <style>
       <!--
        body{
      	   font-size:13px;
      	}
       -->
      </style> 
</head>
<body>
<h1>
<span class="action-span"><a href="${ctx}/system/newscolumn/manage">新闻栏目列表</a></span>
<span class="action-span1"><a href="#">管理中心</a>  - 修改新闻栏目 </span>
<div style="clear:both"></div>
</h1>

<div class="main-div">
  <form:form  modelAttribute="newsColumn" action="${ctx}/system/newscolumn/update" method="post" name="theForm" id="theForm" onsubmit="this.submit.disabled='true';">
  <input type="hidden" name="p_cate_id" id="p_cate_id" value="${newsColumn.parentColumn.id}"/>
  <input type="hidden" name="oldParentColumnId" id="oldParentColumnId" value="${newsColumn.parentColumn.id}"/>
  <input type="hidden" name="oldNewsColumnName" id="oldNewsColumnName" value="${newsColumn.name}"/>
  <input type="hidden" name="oldNewsColumnCode" id="oldNewsColumnCode" value="${newsColumn.code}"/>
  <input type="hidden" name="is_leaf" id="is_leaf" value=""/>
  <form:hidden path="id" />
  <form:hidden path="isLeaf" />
  <form:hidden path="status" />
  <table width="100%" id="general-table">
      <tr>
        <td class="label"><form:label for="name" path="name" cssErrorClass="error">目录名称</form:label></td>
        <td>
          <form:input path="name" maxlength="20" size="27" /> <font color="red">*</font> <form:errors path="name" /></td>
      </tr>
      <tr>
        <td class="label"><form:label for="code" path="code" cssErrorClass="error">目录编码</form:label></td>
        <td><input type="text" name="code" maxlength="20" value="${newsColumn.code}" readonly="readonly" size="27" /> <font color="red">*</font> <form:errors path="code" /></td>
      </tr>
      <tr>
        <td class="label">上级目录</td>
        <td>
	       <div class="cascading-container">
		    <ol id="J_OlCascadingList">
		      <li id="l_1" class="root">
		        <ul id="u_1">
		           <c:choose>
		             <c:when test="${rootNewsColumnId==null}">
		           <li id="-1" class="selected"><span>--根目录--</span></li>
		             </c:when>
		             <c:otherwise>
		           <li id="-1"><span>--根目录--</span></li>
		             </c:otherwise>
		           </c:choose>
		           <c:if test="${rootNewsColumns!=null}">
			           <c:forEach items="${rootNewsColumns}" var="itemTemp">
			             <c:choose>
			                <c:when test="${itemTemp.isLeaf==0}">
					           <c:choose>
					             <c:when test="${rootNewsColumnId==itemTemp.id}">
			           <li id="${itemTemp.id}" class="parent selected"><span>${itemTemp.name}</span></li>
					             </c:when>
					             <c:otherwise>
			           <li id="${itemTemp.id}" class="parent"><span>${itemTemp.name}</span></li>
					             </c:otherwise>
					           </c:choose>
			                </c:when>
			                <c:otherwise>
					           <c:choose>
					             <c:when test="${rootNewsColumnId==itemTemp.id}">
			           <li id="${itemTemp.id}" class="selected"><span>${itemTemp.name}</span></li>
					             </c:when>
					             <c:otherwise>
			           <li id="${itemTemp.id}"><span>${itemTemp.name}</span></li>
					             </c:otherwise>
					           </c:choose>
			                </c:otherwise>
			             </c:choose>
			           </c:forEach>
		           </c:if>
		        </ul>
		      </li>
		      
		      <%
		      @SuppressWarnings("unchecked")
		      List<Long> cateIdList = (List<Long>)request.getAttribute("newsColumnIds");
		      Long newsColumnId = (Long)request.getAttribute("newsColumnId");
		      @SuppressWarnings("unchecked")
		      Map<Long,List<NewsColumn>> parentCateListMap = (Map<Long,List<NewsColumn>>)request.getAttribute("map");
		      if(parentCateListMap!=null && parentCateListMap.keySet().size()>0){
		         int liIndex = 0;
		         for(Long pId:parentCateListMap.keySet()){
		            liIndex++;
		       %>
		                <li id="_o_l_<%=liIndex%>">
		                  <ul id="_o_l_u_<%=liIndex%>">
		       <%
		            List<NewsColumn> cateList = parentCateListMap.get(pId);
		            for(NewsColumn cate:cateList){
		                     if("0".equals(cate.getIsLeaf())){
		                        if(cateIdList.contains(cate.getId())){
		                    %>
		                    <li id="<%=cate.getId()%>" class="parent selected"><span><%=cate.getName()%></span></li>
		                    <%
		                        }else{
		                           if(cate.getId().equals(newsColumnId)){
		                    %>
		                    <li id="<%=cate.getId()%>" class="parent selected"><span><%=cate.getName()%></span><input type="hidden" id="imageTextId<%=cate.getId()%>" value="<%=cate.getIsImageText()%>"/></li>
		                    <%
		                           }else{
		                    %>
		                    <li id="<%=cate.getId()%>" class="parent"><span><%=cate.getName()%></span><input type="hidden" id="imageTextId<%=cate.getId()%>" value="<%=cate.getIsImageText()%>"/></li>
		                    <%
		                           }
		                        }
		                     }else{
		                        if(cateIdList.contains(cate.getId())){
		                    %>
		                    <li id="<%=cate.getId()%>" class="selected"><span><%=cate.getName()%></span></li>
		                    <%
		                        }else{
		                           if(cate.getId().equals(newsColumnId)){
		                    %>
		                    <li id="<%=cate.getId()%>" class="selected"><span><%=cate.getName()%></span><input type="hidden" id="imageTextId<%=cate.getId()%>" value="<%=cate.getIsImageText()%>"/></li>
		                    <%
		                           }else{
		                    %>
		                    <li id="<%=cate.getId()%>"><span><%=cate.getName()%></span><input type="hidden" id="imageTextId<%=cate.getId()%>" value="<%=cate.getIsImageText()%>"/></li>
		                    <%
		                           }
		                        }
		                     }
		          }
		      %>
		                  </ul>
		                </li>
		      <%
		         }
		      }
		      %>
		    </ol>
		  </div>
        </td>
      </tr>

      <tr>
        <td class="label">栏目类型</td>
        <td>
          <form:select path="columnType">
            <c:choose>
              <c:when test="${newsColumn.columnType=='1'}">
            <form:option value="1">普通新闻</form:option>
            <form:option value="2">图文新闻</form:option>
            <form:option value="3">视频新闻</form:option>
              </c:when>
              <c:when test="${newsColumn.columnType=='2'}">
            <form:option value="2">图文新闻</form:option>
            <form:option value="1">普通新闻</form:option>
            <form:option value="3">视频新闻</form:option>
              </c:when>
              <c:when test="${newsColumn.columnType=='3'}">
            <form:option value="3">视频新闻</form:option>
            <form:option value="1">普通新闻</form:option>
            <form:option value="2">图文新闻</form:option>
              </c:when>
              <c:otherwise>
            <form:option value="1">普通新闻</form:option>
            <form:option value="2">图文新闻</form:option>
            <form:option value="3">视频新闻</form:option>
              </c:otherwise>
            </c:choose>
          </form:select>
          </td>
      </tr>
      <tr>
        <td class="label">排序</td>
        <td>
          <form:input path="sortOrder" size="15" /></td>
      </tr>

      <tr>
        <td class="label"><form:label for="desc" path="desc" cssErrorClass="error">描述</form:label></td>
        <td>
          <form:input path="desc" /></td>
      </tr>
      </table>
      <div class="button-div">
        <input type="submit" value=" 确定 " />
        <input type="reset" value=" 重置 " />
      </div>
  </form:form>
</div>
</body>
</html>